<?php
class Model_Assort extends Model{

    public function getInfo(){

        $data=DB::select(array('assortid','id'),'caption','url','pid')

        ->from('assort')->where('isdeleted', '=', '0')

        ->order_by('createdon', 'DESC')

        ->execute()

        ->as_array();

        $result=array();

        foreach ($data as $key => $value) {
        	
        	if($value['pid']==0){

        		$r=array(

        			'id'=>$value['id'],

        			'caption'=>$value['caption'],

        			'pid'=>'0',

        			'url'=>$value['url'],

        			'children'=>array()
        		);

        		foreach ($data as $ckey => $cvalue){

        			if($cvalue['pid']==$value['id']){

        				$r['children'][]=array(

        					'id'=>$cvalue['id'],
        					'caption'=>$cvalue['caption'],
        					'pid'=>$cvalue['pid'],
        					'url'=>$cvalue['url']
        				);
        			}
        		}

        		$result[]=$r;

        	}

        }

        return $result;

    }

    public function getList(){

        $data=DB::select(array('assortid','id'),'caption','url')

        ->from('assort')->where('isdeleted', '=', '0')

        ->order_by('createdon', 'DESC')

        ->execute()

        ->as_array();

        return $data;
    }
}